package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.config.auth.SecurityUtil;
import com.example.domain.BusType;
import com.example.service.BusTypeService;
import com.example.mapper.BusTypeMapper;
import com.example.domain.vo.BusNoteTypeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author CETC
* @description 针对表【bus_type】的数据库操作Service实现
* @createDate 2025-10-21 11:42:56
*/
@Service
public class BusTypeServiceImpl extends ServiceImpl<BusTypeMapper, BusType>
    implements BusTypeService{

    @Override
    public void saveOrUpdateBusType(BusNoteTypeVo busType) {
        String userId= SecurityUtil.getUserId();
        String nodeId= SecurityUtil.getCurrentUserNodeId();
        if(busType.getId()==null){
            BusType bus = new BusType();
            BeanUtils.copyProperties(busType,bus);
            bus.setUserId(userId);
            bus.setIsDeleted(0);
            bus.setDsNo(nodeId);
            this.save(bus);
        }else {
            BusType bus = this.getById(busType.getId());
            if(bus!=null){
                bus.setUserId(userId);
                this.updateById(bus);
            }
        }
    }

    @Override
    public BusType getOneById(String id) {
        BusType bus = this.getById(id);
        return bus;
    }

    @Override
    public List<BusType> getListByUserId(String userId) {
        LambdaQueryWrapper<BusType> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(BusType::getUserId,userId);
        List<BusType> busTypeList=this.list(lambdaQueryWrapper);
        return busTypeList;
    }

    @Override
    public BusType getBusType(String typeId, String userId) {
        LambdaQueryWrapper<BusType> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(BusType::getId,typeId);
        lambdaQueryWrapper.eq(BusType::getUserId,userId);
        return this.getOne(lambdaQueryWrapper);
    }
}




